<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/20
 * Time: 17:21
 */
    namespace Addons\IcWaterGoods\Model;

    class IcGoodsModel extends PublicModel{
        public function getGoodsList($infoType, $goodsType, $page, $size) {
            $where = array();
            $where['status'] = array('neq',0);
            if($goodsType != null) {
                $where = array('good_type'=>$goodsType);
            }

            if($infoType != 0) {
                $where = array_merge($where, array('info_type'=>$infoType));
            }

            $this->where($where);

            return $this
                ->order("create_time desc")
                ->page($page, $size)
                ->select();
        }

        public function remove($id) {
            $msgModel = D('Addons://IcWaterGoods/IcMessage');
            $msgModel->where(array('gid'=>$id))->save(array('status'=>0));
            $this->where(array("id"=>$id))->save(array('status'=>0));
        }

        public function canReleaseByMaxTimesLimit($openid, $maxTimes) {
            if($maxTimes == '') return true;

            // 计算今天的时间
            $time = time();
            $timeStr = date("Y-m-d", $time);
            $time = strtotime($timeStr);

            $where = array(
                'create_time' => array('GT', $time) ,
                'openid' => $openid
            );

            $count = $this->where($where)->count();

            return $maxTimes > $count;
        }
    }